package de.tum.in.eist.poll.client.gui;

import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * Login page
 */
public class LoginPanel extends VerticalPanel {
	private HTML title;
	private TextBox nameTextbox;
	private PasswordTextBox passwordTextbox;
	private PushButton loginButton;
	private HTML errMessage;
//	private final DialogBox dialog = new DialogBox(true);

	/**
	 * Create a login page
	 * 
	 * @param eistPoll
	 *            committed to redirect
	 */
	public LoginPanel() {
		init();
		addContent();
//		initDialog();
	}

	/**
	 * initialize objects, add styles and set the layout
	 */
	private void init() {
		nameTextbox = new TextBox();
		passwordTextbox = new PasswordTextBox();
		loginButton = new PushButton(new Image("/images/LoginButton.png"));
		errMessage = new HTML("");
		title = new HTML("EIST POLL");

		// Add styles
		addStyleName("loginForm");
		nameTextbox.addStyleName("loginNameField");
		passwordTextbox.addStyleName("loginPasswordField");
		loginButton.addStyleName("loginButton");
		errMessage.addStyleName("serverResponseLabelError");
		title.addStyleName("loginTitle");
	}

	/**
	 * Add the objects to the page
	 */
	private void addContent() {
		add(title);

		HorizontalPanel input = new HorizontalPanel();
		input.add(nameTextbox);
		input.add(passwordTextbox);
		input.add(loginButton);

		add(input);
		add(errMessage);
	}
	
	public TextBox getNameTextbox() {
		return nameTextbox;
	}

	public PasswordTextBox getPasswordTextbox() {
		return passwordTextbox;
	}

	public PushButton getLoginButton() {
		return loginButton;
	}

	public HTML getErrMessage() {
		return errMessage;
	}

	public HTML getLoginPanelTitle() {
		return title;
	}

//	private void initDialog() {
//		dialog.setAnimationEnabled(true);
//
//		FlexTable table = new FlexTable();
//		Button register = new Button("Register");
//		Button close = new Button("Close");
//
//		close.addClickHandler(new ClickHandler() {
//			public void onClick(ClickEvent event) {
//				dialog.hide();
//			}
//		});
//		
//		table.setText(0, 0, "The user '" + nameTextbox.getText()
//				+ "' doesn't exist!");
//		table.getFlexCellFormatter().setRowSpan(0, 0, 2);
//		table.setText(1, 0, "Register '" + nameTextbox.getText()
//				+ "' as new user?");
//		table.getFlexCellFormatter().setRowSpan(1, 0, 2);
//		table.setWidget(2, 0, close);
//		table.setWidget(2, 1, register);
//		
//		dialog.add(table);
//	}
//	
//	public void registrationWindow() {
//		System.out.println("Registration window");
//		dialog.setText("Registration");
//		dialog.center();
//	}
}
